Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experimental assert_frame_equal with snapshot support #87

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

15r10nk
Copy link
Owner

@15r10nk 15r10nk commented May 15, 2024

This branch contains a assert_frame_equal which can be used with a snapshot argument.
It uses internal pandas.testing.assert_frame_equal and provides the same arguments.

Important

this branch is experimental and will never be merged into this project.
I keep it here to simplify the development and will provide a separate package which adds pandas support for inline-snapshot when this experiment works out.

You can migrate your code by changing the import

from pandas.testing import assert_frame_equal
from inline_snapshot._pandas import assert_frame_equal

You can use it like this:

from inline_snapshot._pandas import assert_frame_equal

from inline_snapshot import snapshot
from pandas import DataFrame

def test_df():
   df = DataFrame({"col0": [1, 2]})

   # the second argument can be a snapshot,
   assert_frame_equal(df, snapshot())

   # and the generated code looks like this.
   assert_frame_equal(df, snapshot(DataFrame({"col0": {0: 1, 1: 2}})))

   # it can also be used without a snapshot
   assert_frame_equal(df, df)

@Galsor
Copy link

Galsor commented May 16, 2024

The code is not so specific to Pandas.

Seems to me, there is an opportunity for a generic wrapper around custom testing function.
Something like
snapshotify(assert_frame_equal)(df, snapshot())

@Galsor
Copy link

Galsor commented May 16, 2024

Could we imagine the import update to be automatically handled by code gen?

A "testing function" registry could store functions covered by inline-snapshot and facilitate import updates handling.

@15r10nk
Copy link
Owner Author

15r10nk commented May 16, 2024

Seems to me, there is an opportunity for a generic wrapper around custom testing function.
Something like

The implementation is already generic. But I want to keep the imports, because this allows to adopt snapshot capability by changing the imports and keep the calls the same.

Could we imagine the import update to be automatically handled by code gen?

I think that it is easier to replace the imports in your code with the search and replace function of your IDE.

but we could provide a patch_testing_function() function which patches the functions in pandas.testing with the functions which can handle snapshots. A little bit evil, but could be done. This would require no import changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants